// pages/setPassword/setPassword.js
var app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {

  },
  toNextPage(e) {
    if (e.currentTarget.dataset.id == 1) {
      wx.navigateTo({
        url: '../changePassword/changePassword',
      })
    }else {
      wx.navigateTo({
        url: '../resetPassword/resetPassword',
      })
    }
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    wx.request({
      url: app.globalData.baseUrl + '/user/checkPaymentCode',
      data: {
        xcxOpenId: app.globalData.xcxOpenId
      },
      method:'GET',
      header: {
        'content-type': 'application/x-www-form-urlencoded' // 默认值
      },
      success:function(res){
        if(!res.data.data) {
          wx.navigateTo({
            url: '../setNewPassword/setNewPassword'
          })
        }
      }
    })
  },
  onShow(){
    wx.request({
      url: app.globalData.baseUrl + '/user/getUserByOpenId',
      data: {
        xcxOpenId: app.globalData.xcxOpenId
      },
      method: 'GET',
      header: {
        'content-type': 'application/x-www-form-urlencoded' // 默认值
      },
      success: function (res) {
        if (res.data.code == 0) {
          if (!res.data.data.phone) {
            wx.showToast({
              title: '您暂未设置手机号码，请先设置手机号码。',
              icon: 'none'
            })
            setTimeout(function () {
              wx.navigateTo({
                url: '../bindphone/bindphone'
              })
            }, 2000)
          }
        }
      }
    })
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
    wx.reLaunch({
      url: '../me/me',
    })
  }
})